package com.htfyun.serialport;

import com.htfyun.serialport.uartservo.IServoControl;
import com.htfyun.serialport.uartservo.ServoFactory;
import com.htfyun.serialport.utils.SerialDebugLog;

public enum ServoSingleton {
    INSTANCE
    ;

    private IServoControl servoControl;
    private volatile boolean isInited;

    public synchronized void init() {
        if (isInited) {
            return;
        }
        isInited = true;
        servoControl = ServoFactory.produceServoControlForAX12();
    }

    public synchronized void deInit() {
        if (!isInited) {
            return;
        }
        isInited = false;
        if (servoControl != null) {
            servoControl.release();
            servoControl = null;
        }
    }

    public IServoControl getServoControl() {
        init();
        return servoControl;
    }

    public static void setDebuggable(boolean debuggable) {
        SerialDebugLog.setDebuggable(debuggable);
    }

    public static void debugLog(String log) {
        SerialDebugLog.e(log);
    }
}
